import { getSetting, saveSetting } from "@/api/setting";
import { myFile, Setting } from "@/typings";
const accountInfo = uni.getAccountInfoSync();
const appId = accountInfo.miniProgram.appId;

export default {
  namespaced: true,
  state: { version: 0, appId: appId, statement: "" } as Setting,
  mutations: {
    setSetting(state: any, value: Setting) {
      state.version = value.version;
      state.statement = value.statement;
    },
  },
  actions: {
    getSetting({ commit }) {
      getSetting(appId).then((res) => {
        commit("setSetting", res);
      });
    },
    saveSetting({ state }, value: string) {
      state.statement = value;
      saveSetting(state).then((res) => {
        if (res == true) {
          uni.showToast({ title: "保存成功", icon: "success" });
        }
      });
    },
  },
};
